package com.yuqing.sentimentapp.workspace.action;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuqing.sentimentapp.R;
import com.yuqing.sentimentapp.base.BaseActivity;
import com.yuqing.sentimentapp.workspace.action.adapter.ToActionAdapter;
import com.yuqing.sentimentapp.workspace.action.entity.ActionReportResult;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by shenhe on 2020/4/4.
 */
public class ToActionActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;
    private ArrayList<ActionReportResult.DataBean.ReportsBean> dataList;
    private boolean isReported;

    public static void goActivity(Activity activity, ArrayList<ActionReportResult.DataBean.ReportsBean> reportsBeans, boolean isReported) {
        Intent intent = new Intent(activity, ToActionActivity.class);
        intent.putExtra("dataList", reportsBeans);
        intent.putExtra("isReported", isReported);
        activity.startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_to_report;
    }

    @Override
    public void initPresenter() {
        Intent intent = getIntent();
        if (intent == null) return;
        dataList = ((ArrayList<ActionReportResult.DataBean.ReportsBean>) intent.getSerializableExtra("dataList"));
        isReported = intent.getBooleanExtra("isReported", true);

    }

    @Override
    public void initView() {
        if (isReported) {
            mTvTitle.setText(getString(R.string.app_reported_personnel));
        }

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(layoutManager);

        ToActionAdapter mAdapter = new ToActionAdapter(this, dataList, R.layout.item_activity_to_duty);
        mRecyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(data -> {
            if (isReported) {//已上报
                ActionFillInActivity.goActivity(ToActionActivity.this, data);
            }
        });

    }
    @OnClick(R.id.iv_back)
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
